<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge" >
  <title>利用giehub pages 访问github其他项目下的静态页面 | 陈焱林的博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="本篇告诉你如何让我们的github项目实现在线预览。">
<meta property="og:type" content="article">
<meta property="og:title" content="利用giehub pages 访问github其他项目下的静态页面">
<meta property="og:url" content="http://yoursite.com/2016/04/01/利用giehub-pages-访问github其他项目下的静态页面/index.html">
<meta property="og:site_name" content="陈焱林的博客">
<meta property="og:description" content="本篇告诉你如何让我们的github项目实现在线预览。">
<meta property="og:updated_time" content="2016-04-03T08:00:55.767Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="利用giehub pages 访问github其他项目下的静态页面">
<meta name="twitter:description" content="本篇告诉你如何让我们的github项目实现在线预览。">
  
    <link rel="alternative" href="/atom.xml" title="陈焱林的博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/img/favicon.ico">
  
  <link rel="stylesheet" href="/css/style.css">
  
	<script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan style='display:none;' id='cnzz_stat_icon_1258379977'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s4.cnzz.com/z_stat.php%3Fid%3D1258379977' type='text/javascript'%3E%3C/script%3E"));</script>


</head>

<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
	<header id="header" class="inner">
		<a href="/" class="profilepic">
			
			<img lazy-src="/img/me.png" class="js-avatar">
			
		</a>

		<hgroup>
		  <h1 class="header-author"><a href="/">linvic</a></h1>
		</hgroup>

		
		<p class="header-subtitle">陈焱林github博客</p>
		

		
			<div class="switch-btn">
				<div class="icon">
					<div class="icon-ctn">
						<div class="icon-wrap icon-house" data-idx="0">
							<div class="birdhouse"></div>
							<div class="birdhouse_holes"></div>
						</div>
						<div class="icon-wrap icon-ribbon hide" data-idx="1">
							<div class="ribbon"></div>
						</div>
						
						
						<div class="icon-wrap icon-me hide" data-idx="3">
							<div class="user"></div>
							<div class="shoulder"></div>
						</div>
						
					</div>
					
				</div>
				<div class="tips-box hide">
					<div class="tips-arrow"></div>
					<ul class="tips-inner">
						<li>菜单</li>
						<li>标签</li>
						
						
						<li>关于我</li>
						
					</ul>
				</div>
			</div>
		

		<div class="switch-area">
			<div class="switch-wrap">
				<section class="switch-part switch-part1">
					<nav class="header-menu">
						<ul>
						
							<li><a href="/">主页</a></li>
				        
							<li><a href="/archives">所有文章</a></li>
				        
							<li><a href="/tags/随笔/">随笔</a></li>
				        
						</ul>
					</nav>
					<nav class="header-nav">
						<div class="social">
							
								<a class="github" target="_blank" href="https://github.com/linvic" title="github">github</a>
					        
								<a class="weibo" target="_blank" href="#" title="weibo">weibo</a>
					        
								<a class="rss" target="_blank" href="#" title="rss">rss</a>
					        
						</div>
					</nav>
				</section>
				
				
				<section class="switch-part switch-part2">
					<div class="widget tagcloud" id="js-tagcloud">
						<a href="/tags/GitHub/" style="font-size: 20px;">GitHub</a> <a href="/tags/Hexo/" style="font-size: 15px;">Hexo</a> <a href="/tags/pages/" style="font-size: 10px;">pages</a> <a href="/tags/移动web/" style="font-size: 10px;">移动web</a> <a href="/tags/随笔/" style="font-size: 10px;">随笔</a>
					</div>
				</section>
				
				
				

				
				
				<section class="switch-part switch-part3">
				
					<div id="js-aboutme">南昌大学共青学院12级,前端开发爱好者,喜欢新鲜事物喜欢coding,期望在前端道路上大大的迈步!</div>
				</section>
				
			</div>
		</div>
	</header>				
</div>

    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
  	<div class="overlay">
  		<div class="slider-trigger"></div>
  		<h1 class="header-author js-mobile-header hide">linvic</h1>
  	</div>
	<div class="intrude-less">
		<header id="header" class="inner">
			<div class="profilepic">
			
				<img lazy-src="/img/me.png" class="js-avatar">
			
			</div>
			<hgroup>
			  <h1 class="header-author">linvic</h1>
			</hgroup>
			
			<p class="header-subtitle">陈焱林github博客</p>
			
			<nav class="header-menu">
				<ul>
				
					<li><a href="/">主页</a></li>
		        
					<li><a href="/archives">所有文章</a></li>
		        
					<li><a href="/tags/随笔/">随笔</a></li>
		        
		        <div class="clearfix"></div>
				</ul>
			</nav>
			<nav class="header-nav">
				<div class="social">
					
						<a class="github" target="_blank" href="https://github.com/linvic" title="github">github</a>
			        
						<a class="weibo" target="_blank" href="#" title="weibo">weibo</a>
			        
						<a class="rss" target="_blank" href="#" title="rss">rss</a>
			        
				</div>
			</nav>
		</header>				
	</div>
</nav>

      <div class="body-wrap"><article id="post-利用giehub-pages-访问github其他项目下的静态页面" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2016/04/01/利用giehub-pages-访问github其他项目下的静态页面/" class="article-date">
  	<time datetime="2016-04-01T07:10:20.000Z" itemprop="datePublished">2016-04-01</time>
</a>
    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      利用giehub pages 访问github其他项目下的静态页面
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
	<div class="article-tag tagcloud">
		<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/GitHub/">GitHub</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/pages/">pages</a></li></ul>
	</div>

        

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="本篇告诉你如何让我们的github项目实现在线预览。"><a href="#本篇告诉你如何让我们的github项目实现在线预览。" class="headerlink" title="本篇告诉你如何让我们的github项目实现在线预览。"></a>本篇告诉你如何让我们的github项目实现在线预览。</h3><a id="more"></a>
<p>我们都知道，咱们的项目push到github上面的时候，我们看到的是源代码，可是有时候我们想将我们项目的效果展示给他人时，就会想，<strong>如果github能够实时预览项目效果那该多好？</strong></p>
<p>但是其实github pages可以解决我们这个问题。<br>先来讲下原理：咱们利用gh-pages分支，将需要预览的项目push到这个分支中，就可以实现在线预览项目效果了！</p>
<p>原理看懂了得大神应该已经明白了，下面的详细步骤适合还是没懂的朋友。</p>
<p>关于github pages的创建过程我这里就不复述了，我前面的博客搭建教程中有的。</p>
<p><strong>本篇前提：</strong></p>
<ul>
<li>拥有github pages</li>
</ul>
<ol>
<li><p>首先，我在github中新建了一个名为”demo”的项目，新建之后这里当然是没有内容的，咱们留着SSH备用（git@github.com:linvic/demo.git）</p>
</li>
<li><p>然后咱们新建一个文件夹（我在我电脑新建了一个E:demo）</p>
</li>
<li><p>打开“Git Shell”（或者git bash） cd到咱们的本地项目文件夹下，初始化本地项目。相关命令如下：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd E:demo</span><br><span class="line">git init</span><br><span class="line">git remote add origin git@github.com:linvic/demo.git</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p><em>把上面的项目地址换成你自己的</em></p>
<ol>
<li>我们新建立一个html文件进行测试，我在<code>E:demo</code>下新建了一个test.html，内容随便放点。</li>
</ol>
<p><strong>接着，主角登场~</strong></p>
<ol>
<li>然后回到“Git Shell”（或者git bash）。新建一个“gh-pages”的分支，然后将当前项目下的文件都push到远程仓库。相关命令如下：<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git checkout -b gh-pages</span><br><span class="line">git add *</span><br><span class="line">git commit -m 'test'</span><br><span class="line">git push origin gh-pages</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>这样，咱们再访问pages主页/项目名/文件名(如：linvic.github.io/demo/test.html)就能直接预览代码效果了！</p>
<p>PS：这篇文章为了方便我们是直接新建一个仓库进行测试，实际应用中大家可以先将自己远程库中的项目<code>$ git clone</code>到本地，然后新建gh-pages分支，再push到gh-pages分支即可！</p>
<p>好了，如果有问题欢迎留言哦。</p>

      
    </div>
    
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2016/04/12/移动WEB学习笔记/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption"><</strong>
      <div class="article-nav-title">
        
          移动WEB学习笔记
        
      </div>
    </a>
  
  
    <a href="/2016/03/29/GitHub-Hexo搭建博客教程之给博客设置个性域名/" id="article-nav-older" class="article-nav-link-wrap">
      <div class="article-nav-title">GitHub+Hexo搭建博客教程之给博客设置个性域名.md</div>
      <strong class="article-nav-caption">></strong>
    </a>
  
</nav>

  
</article>


<div class="share_jia">
	<!-- JiaThis Button BEGIN -->
	<div class="jiathis_style">
		<span class="jiathis_txt">分享到: &nbsp; </span>
		<a class="jiathis_button_facebook"></a> 
    <a class="jiathis_button_twitter"></a>
    <a class="jiathis_button_plus"></a> 
    <a class="jiathis_button_tsina"></a>
		<a class="jiathis_button_cqq"></a>
		<a class="jiathis_button_douban"></a>
		<a class="jiathis_button_weixin"></a>
		<a class="jiathis_button_tumblr"></a>
    <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	</div>
	<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js?uid=1405949716054953" charset="utf-8"></script>
	<!-- JiaThis Button END -->
</div>






<div class="duoshuo">
	<!-- 多说评论框 start -->
	<div class="ds-thread" data-thread-key="利用giehub-pages-访问github其他项目下的静态页面" data-title="利用giehub pages 访问github其他项目下的静态页面" data-url="http://yoursite.com/2016/04/01/利用giehub-pages-访问github其他项目下的静态页面/"></div>
	<!-- 多说评论框 end -->
	<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
	<script type="text/javascript">
	var duoshuoQuery = {short_name:"linvic"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
	<!-- 多说公共JS代码 end -->
</div>




</div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info">
    	<div class="footer-left">
    		&copy; 2016 linvic
    	</div>
      	<div class="footer-right">
      		by <b style="color:#42A4FF">陈焱林</b> Email:674206994@qq.com
      	</div>
    </div>
  </div>
</footer>
    </div>
    
  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">


<script>
	var yiliaConfig = {
		fancybox: true,
		mathjax: true,
		animate: true,
		isHome: false,
		isPost: true,
		isArchive: false,
		isTag: false,
		isCategory: false,
		open_in_new: false
	}
</script>
<script src="http://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script>
<script src="/js/main.js"></script>






<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    }
});

MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';                 
    }       
});
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  </div>
</body>
</html>